package com.zy.openchat.core.model.message;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;
import java.util.List;

public class TextInfo implements Parcelable {

    public List<TextEntity> entities;

    public static TextInfo buildRemittedRemindTextInfo(long remittanceId,String startText,String endText){
        TextInfo textInfo = new TextInfo();
        TextEntity textEntity = new TextEntity();
        textEntity.length = endText.length();
        textEntity.offset = startText.length();
        TextEntityType textEntityType = new TextEntityType();
        textEntityType.type = TextEntityType.RemiitedType;
        textEntityType.remittanceId = remittanceId;
        textEntity.type = textEntityType;
        List<TextEntity> entities = new ArrayList<>();
        entities.add(textEntity);
        textInfo.entities = entities;
        return textInfo;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeList(this.entities);
    }

    public void readFromParcel(Parcel source) {
        this.entities = new ArrayList<TextEntity>();
        source.readList(this.entities, TextEntity.class.getClassLoader());
    }

    public TextInfo() {
    }

    protected TextInfo(Parcel in) {
        this.entities = new ArrayList<TextEntity>();
        in.readList(this.entities, TextEntity.class.getClassLoader());
    }

    public static final Creator<TextInfo> CREATOR = new Creator<TextInfo>() {
        @Override
        public TextInfo createFromParcel(Parcel source) {
            return new TextInfo(source);
        }

        @Override
        public TextInfo[] newArray(int size) {
            return new TextInfo[size];
        }
    };
}
